<?php
session_start();

if(!isset($_SESSION['id'])){
	header('Location:login.php');
}
/*	$xmname=$_POST['xmname'];
	$ename=$_POST['ename'];
	$id=$_POST['id'];
	$manage=$_POST['manage'];

	$connect=mysql_connect('localhost','root','');
	mysql_select_db('shenji',$connect);
	mysql_query("set names utf8");
	$sql="update type set name='$xmname',ename='$ename',manage='$manage'where typeid='$id'";
	mysql_query($sql);
	
	echo "<script>location='select_xiangmu.php';</script>";*/
	if(isset($_POST['submit'])){
		$xmname=$_POST['xmname'];
		$ename=$_POST['ename'];
		$manage=$_POST['manage'];
		$id=$_POST['id'];
		if($xmname==""||$ename==""){
			echo "<script>alert('名称不能为空');history.go(-1);</script>";
		}elseif(!preg_match("/^[\x{4e00}-\x{9fa5}]{2,5}+$/u", $xmname)){
			echo "<script>alert('名称格式不正确，由中文且长度为2~5个字符');history.go(-1);</script>";
		}elseif(!preg_match("/^[a-zA-Z]+$/", $ename)){
			echo "<script>alert('英文名称格式不正确(最好为其中文对应的名称)');history.go(-1);</script>";
		}else{
			$db=new PDO("mysql:host=localhost;dbname=shenji","root","");
			$db->setAttribute(PDO::ATTR_EMULATE_PREPARES,false);
			$db->exec("set names utf8");
			$result=$db->exec("update type set name='$xmname',ename='$ename',manage='$manage'where typeid='$id'");
		}
		echo "<script>location='select_xiangmu.php';</script>";
	}
?>